CREATE
OR REPLACE PROCEDURE bsps_insert_tbjdfxpg(p_phid IN NUMBER) 
AS 
    gzxm_phid BIGINT; -- 跟踪项目计划id
    yzdw_name VARCHAR(255); -- 跟踪计划的业主单位phid
    one_hylb BIGINT; -- 一级行业类别
BEGIN
    -- 查找跟踪项目信息的phid
    SELECT user_bdmc INTO gzxm_phid FROM crm3_tend_file where phid = p_phid;
    SELECT u_yzdw,u_hylb INTO yzdw_name,one_hylb FROM p_form_gzxmxx_m where phid = gzxm_phid;
    INSERT INTO p_form_tbjdfxpg_m(
        phid,
        phid_org,
        u_basp,
        u_xmmc,
        u_djly,
        bill_no,
        u_bdmc,
        u_ssdw,
        phid_fill_psn,
        bill_dt,
        app_status,
        ng_insert_dt,
        ng_update_dt,
        ng_record_ver,
        wf_flag
    )
    SELECT
        seq_auto_phid_bsps_tbjdfxpg.nextval,
        phid_org,
        '分公司',
        user_xmmc,
        p_phid,
        bill_no,
        user_bdmc,
        phid_org,
        user_sqr,
        TRUNC(SYSDATE),
        0,
        TRUNC(SYSDATE),
        TRUNC(SYSDATE),
        2,
        0
    FROM crm3_tend_file
    WHERE phid = p_phid;
    commit;
    EXCEPTION 
    WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('插入失败，错误信息：' || SQLERRM);
    RAISE;
    ROLLBACK;
END bsps_insert_tbjdfxpg;